﻿#include "timeDialog.h"
#include "ui_timeDialog.h"

#include "SqliteOperator.h"

#include "widget.h"


TimeDialog::TimeDialog(QWidget *parent) :QDialog(parent),ui(new Ui::TimeDialog)
{
    ui->setupUi(this);
    m_parent =(Widget *)parentWidget();
    QTime time1 ;
    time1.setHMS(18,00,00);
    ui->everyDayTimeEdit->setTime(time1);

    QMap<QString, int> modeMap;
    modeMap.insert("关机",1);
    modeMap.insert("睡眠",2);
    ui->modeCBox->clear();
    foreach(const QString &str,modeMap.keys()){
        ui->modeCBox->addItem(str,modeMap.value(str));
    }

}



TimeDialog::~TimeDialog()
{
    delete ui;
}

void TimeDialog::on_SavePBtn_clicked()
{
    int mode=ui->modeCBox->currentData().toInt() ;//项关联的数据
    //创建并打开SQLite数据库
    SqliteOperator sqlOper;
    sqlOper.openDb();
    TaskMain taskMain;
    taskMain.createTime=QDateTime::currentDateTime().toMSecsSinceEpoch();
    taskMain.intervalType = 2;
//    w2dba1.taskTime = ui->everyDayTimeEdit->dateTime().toMSecsSinceEpoch();
    QTime time1 =  ui->everyDayTimeEdit->time();
    long long taskTime = time1.hour()*60*60 + time1.minute()*60 + time1.second();
    taskMain.taskTime =taskTime;
    taskMain.statusFlag=1;
    taskMain.mode=mode;
    sqlOper.singleInsertData(taskMain);
    sqlOper.closeDb();

    emit ExitWin();

    this->close();
}


void TimeDialog::on_canclePTtn_clicked()
{
    this->close();
}



